#import "DDFS.h"
#import "DDFSModel.h"
@interface DDFS()
@property (nonatomic, strong) CCLabel *leftLBL;
@property (nonatomic, strong) CCLabel *rightLBL;
@end
@implementation DDFS
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.leftLBL.text = @"支付选择";
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}
- (CCLabel *)leftLBL
{
    if (!_leftLBL)
    {
        _leftLBL = [[CCLabel alloc] init];
        _leftLBL.font = FONT(UIFontWeightRegular, 15);
        _leftLBL.textColor = TEXT_BLACK_COLOR;
        [self addSubview:_leftLBL];
        _leftLBL.c_left.c_equal(self).with.coffset(GAP);
        _leftLBL.c_top.c_equal(self).with.coffset(GAP);
    }
    return _leftLBL;
}
- (CCLabel *)rightLBL
{
    if (!_rightLBL)
    {
        _rightLBL = [[CCLabel alloc] init];
        _rightLBL.font = FONT(UIFontWeightRegular, 15);
        _rightLBL.textColor = [DDHelper help].color;
        [self addSubview:_rightLBL];
        _rightLBL.c_right.c_equal(self).with.coffset(-GAP);
        _rightLBL.c_top.c_equal(self).with.coffset(GAP);
    }
    return _rightLBL;
}
- (void)setFs:(NSMutableArray<DDFSModel *> *)fs
{
    if (_fs != fs)
    {
        _fs = fs;
        [self setupSubView];
    }
}
- (void)setJiage:(NSString *)jiage
{
    if (_jiage != jiage)
    {
        _jiage = jiage;
        self.rightLBL.text = _jiage;
    }
}
- (void)setupSubView
{
    for (int i = 0; i <self.fs.count; i++)
    {
        DDFSItem *fsView = [[DDFSItem alloc] init];
        fsView.model = self.fs[i];
        fsView.tag = 200 + [fsView.model.ID intValue];
        [fsView addTarget:self action:@selector(dd_actionForZFFS:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:fsView];
        fsView.c_top.c_equal(self).with.coffset(JTWFSItemHEIGHT * (i+1));
        fsView.c_left.c_equal(self).with.coffset(GAP);
        fsView.c_right.c_equal(self).with.coffset(-GAP);
        fsView.c_height.c_equal(JTWFSItemHEIGHT);
    }
}
- (void)dd_actionForZFFS:(DDFSItem *)sender
{
    for (UIView *view in [self subviews])
    {
        if (view.tag > 200)
        {
            DDFSItem *fsView = (DDFSItem *)view;
            fsView.selected = (fsView.tag == sender.tag)?YES:NO;
        }
    }
    self.currentIndex = (sender)?((int)sender.tag - 200):0;
    if (self.delegate  && [self.delegate respondsToSelector:@selector(dd_actionForJTWFSDelegate)])
    {
        [self.delegate dd_actionForJTWFSDelegate];
    }
}
- (void)dd_ergodic:(NSInteger )tag
{
    for (UIView *view in [self subviews])
    {
        if (view.tag > 200)
        {
            DDFSItem *fsView = (DDFSItem *)view;
            fsView.selected = (view.tag == tag)?YES:NO;
        }
    }
}
- (void)setCurrentIndex:(int)currentIndex
{
    if (_currentIndex != currentIndex)
    {
        _currentIndex = currentIndex;
        [self performSelector:@selector(dd_actionForZFFS:) withObject:[self viewWithTag:_currentIndex + 200]];
    }
}
@end
